package com.zjc.yohoshop.mvp.view.adapter;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.zjc.yohoshop.R;
import com.zjc.yohoshop.bean.CommunityEntity;
import com.zjc.yohoshop.network.API;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class CommunityAdaptrr extends BaseMultiItemQuickAdapter<CommunityEntity.ValuesBean, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public CommunityAdaptrr(List<CommunityEntity.ValuesBean> data) {
        super(data);
        addItemType(CommunityEntity.Community0, R.layout.item_community_0);
        addItemType(CommunityEntity.Community1, R.layout.item_community_1);
    }

    @Override
    protected void convert(BaseViewHolder helper, CommunityEntity.ValuesBean item) {
        if (helper.getItemViewType() == CommunityEntity.Community0){
            RoundedImageView riv_item_community_icon0 = helper.getView(R.id.riv_item_community_icon0);
            Glide.with(helper.itemView.getContext()).load(API.BaseUrl + "/head_img/wzh_head.png").into(riv_item_community_icon0);
            RoundedImageView riv_item_community_img0 = helper.getView(R.id.riv_item_community_img0);
            Glide.with(helper.itemView.getContext()).load(API.BaseUrl + "/recommend_img/recommend1.jpg").into(riv_item_community_img0);

            helper.setText(R.id.tv_item_community_name0, item.community_values);
            helper.setText(R.id.tv_item_community_collection0, item.collection);
            helper.setText(R.id.tv_item_community_tag0, item.tag);
            helper.setText(R.id.tv_item_community_title0, item.title);
            helper.setText(R.id.tv_item_community_hot_flag0, item.hot_flag);

            Date date = new Date(Long.parseLong(item.community_time));
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM月dd日 kk:mm");
            String time = simpleDateFormat.format(date);
            helper.setText(R.id.tv_item_community_time0, time);

        }else if (helper.getItemViewType() == CommunityEntity.Community1){
            RoundedImageView riv_item_community_icon1 = helper.getView(R.id.riv_item_community_icon1);
            Glide.with(helper.itemView.getContext()).load(API.BaseUrl + "/head_img/wzh_head.png").into(riv_item_community_icon1);
            RoundedImageView riv_item_community_img1 = helper.getView(R.id.riv_item_community_img1);
            Glide.with(helper.itemView.getContext()).load(API.BaseUrl + "/recommend_img/recommend1.jpg").into(riv_item_community_img1);

            helper.setText(R.id.tv_item_community_name1, item.community_values);
            helper.setText(R.id.tv_item_community_collection1, item.collection);
            helper.setText(R.id.tv_item_community_tag1, item.tag);
            helper.setText(R.id.tv_item_community_title1, item.title);
            helper.setText(R.id.tv_item_community_hot_flag1, item.hot_flag);

            Date date = new Date(Long.parseLong(item.community_time));
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM月dd日 kk:mm");
            String time = simpleDateFormat.format(date);
            helper.setText(R.id.tv_item_community_time1, time);
        }
    }
}
